/*
 * gsmmux.h -- header file of functions for gsmmux
 *
 * Copyright (C) 2007 lufang <lufang@gmail.com>
 *
 * Version 1.0 june 2007
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#ifndef _GSMMUX_H
#define	_GSMMUX_H

#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include "buffer.h"

#define GSMMUX_MAX_USSP_FD_COUNT	32

typedef struct _GsmModule GsmModule;
typedef struct _GsmModuleGenerator GsmModuleGenerator;

enum
{
	USSP_PORT_AT,
	USSP_PORT_DATA,
	USSP_PORT_CTRL,
	USSP_PORT_NR
};

typedef struct _VirtualPortInfo
{
	int             ussp_fds[GSMMUX_MAX_USSP_FD_COUNT + 1];
	char*			ussp_name[GSMMUX_MAX_USSP_FD_COUNT + 1];
}VirtualPortInfo;

struct _GsmModule
{
	/*public data*/
	GSM0710_Buffer*	in_buf;
	int				serial_fd;
	VirtualPortInfo	vir_ports;
	pthread_t		thread_id;

	char*			device_name;
	char*			vir_prefix;

	/*viturl func*/
	int		(*module_destroy) (GsmModule* thiz);
	
	int         (*write_frame) (GsmModule* thiz, int channel, 
						const unsigned char* input, int count, unsigned char type);
	int			(*write_ussp_data) (GsmModule* thiz, int channel, 
						const unsigned char* input, int count);

	void*			priv;
};


struct _GsmModuleGenerator
{
	GsmModule*				(* create_module_func) (GsmModuleGenerator* generator, const char* device_name);
	int						(* match_func) (GsmModuleGenerator* generator, const char* type);
	void					(* destroy_func) (GsmModuleGenerator* generator);
};

GsmModule* gsm_module_create (const char* module_type, const char* device_name);
int			gsm_module_get_ussp_fd(GsmModule* module, int port);
void		gsm_module_reopen_ussp_fd(GsmModule* module, int port);
void gsm_module_destroy (GsmModule* module);


typedef GsmModuleGenerator* (* GeneratorCreateFunc) ();

#endif

